package com.ruoyi.websocket.service;

import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ruoyi.cfuser.api.rescue.RemoteInitiateService;
import com.ruoyi.cfuser.api.rescue.domain.RescueTask;
import com.ruoyi.shop.api.domain.Shop;
import com.ruoyi.websocket.controller.WebSocketController;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class SendMessageToUserService {

    @Resource
    private RemoteInitiateService remoteInitiateService;
    @Resource
    private WebSocketService webSocketService;

    public void sendMessage(Map<String,Object> map){
        ObjectMapper objectMapper = new ObjectMapper();
        Shop shopInfo = objectMapper.convertValue(map.get("shopInfo"), Shop.class);
        String uid = objectMapper.convertValue(map.get("uid"), String.class);
        webSocketService.sendMessage("user"+uid,JSON.toJSONString(shopInfo));
    }
}
